Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ops that are not in parameters from tokenize_partial #368

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

phofl
Copy link
Collaborator

@phofl phofl commented Oct 26, 2023

cc @rjzamora

I'd rather include those than include them. We don't care about those at the moment, we can still add an option if we want them at some point, but they cause trouble with the multi-column assign

@rjzamora
Copy link
Member

I’m not looking at the code at the moment, so I may need to revise later. However, I’m slightly confused about this. Don’t “unnamed” operands typically refer to blockwise dependencies that may be Expr objects? Wouldn’t these dependencies be an important part of the token?

@phofl
Copy link
Collaborator Author

phofl commented Oct 27, 2023

I agree generally speaking, but we are only using this in combine_similar at the moment where we definitely want to ignore other expressions in most cases (all cases at the moment). I am open to introduce an option to configure this if we need it at a later point.

@rjzamora
Copy link
Member

where we definitely want to ignore other expressions in most cases (all cases at the moment).

Interesting. I'll try to think about and review this change now, and then I'll probably agree with you. My current question is "how can we combine two expressions that depend on different operands? That would be a bug", but a review of the code may clear this up for me.

I am open to introduce an option to configure this if we need it at a later point.

Yeah, that makes sense. Would it be overkill to add an ignore_unnamed=True kwarg to make it explicit that we are ignoring operands that are not explicitly named in parameters?

@phofl
Copy link
Collaborator Author

phofl commented Oct 27, 2023

Yeah, that makes sense. Would it be overkill to add an ignore_unnamed=True kwarg to make it explicit that we are ignoring operands that are not explicitly named in parameters?

Sure, we wouldn't be using it which turned me away from it, but not generally opposed

My current question is "how can we combine two expressions that depend on different operands?

Merge is modifying 2 at once to make this possible. I assume that we will have to go a similar route for concat. A multi-column assign is tricky as well, don't have a good solution yet

Copy link
Member

@rjzamora rjzamora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I just got a chance to look through the code and I think I understand why you are saying that we don't need to consider unnamed operands.

If I understand correctly, the change should probably be in _find_similar_operations instead of _tokenize_partial. It seems like _tokenize_partial is used in places like are_co_aligned, where it is possible that we really do care about unnamed operands. In _find_similar_operations, however, we really don't care about these operands, because the only place where were aren't effectively using _find_similar_operations as a proxy for find_operations is in BlockwiseIO (where there are not unnamed parameters anyway).

My suggestion is that we change the ignore: list | None argument to ignore_operands: list | bool in _find_similar_operations. E.g.:

de _find_similar_operations(self, root: Expr, ignore_operands: list | bool = True):
    ....

If ignore_operands=True is specified, we don't need to call _tokenize_partial at all, because alike already includes all "similar" operations when its operands are ignored. I'm not sure that there is a case where ignore_operands=False makes sense, but we would just pass through ignore=None to _tokenize_partial.

Does this make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants